package com.boot.main.service.impl;

import com.boot.main.entity.BcomCategory;
import com.boot.main.mapper.BcomCategoryMapper;
import com.boot.main.response.ResponseData;
import com.boot.main.response.ResponseDataUtil;
import com.boot.main.service.IBlogCategoryService;
import com.boot.main.utils.IsNotEmptyUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

@Service
public class BlogCategoryService implements IBlogCategoryService {
    @Resource
    private BcomCategoryMapper categoryMapper;

    @Override
    public ResponseData getCategorys(Integer status){
        List<BcomCategory> items = categoryMapper.getCategorys(status);
        return ResponseDataUtil.success("获取分类成功", items);
    }

    @Override
    public ResponseData saveCategory(BcomCategory category){
        category.setCreate_time(new Date().getTime());
        Integer num = categoryMapper.saveCategory(category);
        if(IsNotEmptyUtil.isEmpty(num)){
            return ResponseDataUtil.error("保存分类失败", null);
        }
        return ResponseDataUtil.success("保存分类成功", null);
    }

    @Override
    public ResponseData updateCategory(BcomCategory category){
        category.setCreate_time(new Date().getTime());
        Integer num = categoryMapper.updateCategory(category);
        if(IsNotEmptyUtil.isEmpty(num)){
            return ResponseDataUtil.error("修改分类失败", null);
        }
        return ResponseDataUtil.success("修改分类成功", null);
    }

    @Override
    public ResponseData deleteCategory(Long id){
        Integer num = categoryMapper.deleteCategory(id);
        return ResponseDataUtil.success("删除分类成功", null);
    }
}
